{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "args = {\n",
    "    'data_path': r\"D:/Jupyter/pytorch/d2l-zh/pytorch/appppppp/detection2/test\",\n",
    "    'output_file': \"./output/predictions.csv\",  # 改为csv格式\n",
    "    'weight_file': r\"E:/download/MinneApple-master/MinneApple-master/MinneApple-master/myapple101.pth\",\n",
    "    'device': \"cuda\",\n",
    "    'model_type': 'mrcnn'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Renamed  compared“”\n",
      "Renamed  dataset1_back_1“”\n",
      "Renamed  dataset1_back_1021“”\n",
      "Renamed  dataset1_back_1051“”\n",
      "Renamed  dataset1_back_1081“”\n",
      "Renamed  dataset1_back_1111“”\n",
      "Renamed  dataset1_back_1141“”\n",
      "Renamed  dataset1_back_1171“”\n",
      "Renamed  dataset1_back_1201“”\n",
      "Renamed  dataset1_back_121“”\n",
      "Renamed  dataset1_back_151“”\n",
      "Renamed  dataset1_back_181“”\n",
      "Renamed  dataset1_back_241“”\n",
      "Renamed  dataset1_back_271“”\n",
      "Renamed  dataset1_back_301“”\n",
      "Renamed  dataset1_back_31“”\n",
      "Renamed  dataset1_back_331“”\n",
      "Renamed  dataset1_back_361“”\n",
      "Renamed  dataset1_back_391“”\n",
      "Renamed  dataset1_back_421“”\n",
      "Renamed  dataset1_back_451“”\n",
      "Renamed  dataset1_back_481“”\n",
      "Renamed  dataset1_back_511“”\n",
      "Renamed  dataset1_back_541“”\n",
      "Renamed  dataset1_back_571“”\n",
      "Renamed  dataset1_back_601“”\n",
      "Renamed  dataset1_back_61“”\n",
      "Renamed  dataset1_back_631“”\n",
      "Renamed  dataset1_back_661“”\n",
      "Renamed  dataset1_back_691“”\n",
      "Renamed  dataset1_back_721“”\n",
      "Renamed  dataset1_back_751“”\n",
      "Renamed  dataset1_back_781“”\n",
      "Renamed  dataset1_back_811“”\n",
      "Renamed  dataset1_back_841“”\n",
      "Renamed  dataset1_back_871“”\n",
      "Renamed  dataset1_back_901“”\n",
      "Renamed  dataset1_back_91“”\n",
      "Renamed  dataset1_back_931“”\n",
      "Renamed  dataset1_back_961“”\n",
      "Renamed  dataset1_back_991“”\n",
      "Renamed  dataset1_front_1“”\n",
      "Renamed  dataset1_front_1021“”\n",
      "Renamed  dataset1_front_1051“”\n",
      "Renamed  dataset1_front_1081“”\n",
      "Renamed  dataset1_front_1111“”\n",
      "Renamed  dataset1_front_1141“”\n",
      "Renamed  dataset1_front_1171“”\n",
      "Renamed  dataset1_front_1201“”\n",
      "Renamed  dataset1_front_121“”\n",
      "Renamed  dataset1_front_1231“”\n",
      "Renamed  dataset1_front_1261“”\n",
      "Renamed  dataset1_front_1291“”\n",
      "Renamed  dataset1_front_1321“”\n",
      "Renamed  dataset1_front_1351“”\n",
      "Renamed  dataset1_front_1381“”\n",
      "Renamed  dataset1_front_1411“”\n",
      "Renamed  dataset1_front_1441“”\n",
      "Renamed  dataset1_front_1471“”\n",
      "Renamed  dataset1_front_1501“”\n",
      "Renamed  dataset1_front_151“”\n",
      "Renamed  dataset1_front_1531“”\n",
      "Renamed  dataset1_front_1561“”\n",
      "Renamed  dataset1_front_1651“”\n",
      "Renamed  dataset1_front_181“”\n",
      "Renamed  dataset1_front_211“”\n",
      "Renamed  dataset1_front_241“”\n",
      "Renamed  dataset1_front_271“”\n",
      "Renamed  dataset1_front_301“”\n",
      "Renamed  dataset1_front_31“”\n",
      "Renamed  dataset1_front_331“”\n",
      "Renamed  dataset1_front_361“”\n",
      "Renamed  dataset1_front_391“”\n",
      "Renamed  dataset1_front_421“”\n",
      "Renamed  dataset1_front_451“”\n",
      "Renamed  dataset1_front_481“”\n",
      "Renamed  dataset1_front_511“”\n",
      "Renamed  dataset1_front_541“”\n",
      "Renamed  dataset1_front_571“”\n",
      "Renamed  dataset1_front_601“”\n",
      "Renamed  dataset1_front_61“”\n",
      "Renamed  dataset1_front_631“”\n",
      "Renamed  dataset1_front_661“”\n",
      "Renamed  dataset1_front_691“”\n",
      "Renamed  dataset1_front_721“”\n",
      "Renamed  dataset1_front_751“”\n",
      "Renamed  dataset1_front_781“”\n",
      "Renamed  dataset1_front_811“”\n",
      "Renamed  dataset1_front_841“”\n",
      "Renamed  dataset1_front_871“”\n",
      "Renamed  dataset1_front_901“”\n",
      "Renamed  dataset1_front_91“”\n",
      "Renamed  dataset1_front_931“”\n",
      "Renamed  dataset1_front_961“”\n",
      "Renamed  dataset1_front_991“”\n",
      "Renamed  dataset2_back_0“”\n",
      "Renamed  dataset2_back_1020“”\n",
      "Renamed  dataset2_back_1050“”\n",
      "Renamed  dataset2_back_1080“”\n",
      "Renamed  dataset2_back_1110“”\n",
      "Renamed  dataset2_back_1140“”\n",
      "Renamed  dataset2_back_1170“”\n",
      "Renamed  dataset2_back_120“”\n",
      "Renamed  dataset2_back_1200“”\n",
      "Renamed  dataset2_back_1230“”\n",
      "Renamed  dataset2_back_1260“”\n",
      "Renamed  dataset2_back_1290“”\n",
      "Renamed  dataset2_back_1320“”\n",
      "Renamed  dataset2_back_1350“”\n",
      "Renamed  dataset2_back_1380“”\n",
      "Renamed  dataset2_back_1410“”\n",
      "Renamed  dataset2_back_1440“”\n",
      "Renamed  dataset2_back_1470“”\n",
      "Renamed  dataset2_back_150“”\n",
      "Renamed  dataset2_back_1500“”\n",
      "Renamed  dataset2_back_180“”\n",
      "Renamed  dataset2_back_210“”\n",
      "Renamed  dataset2_back_240“”\n",
      "Renamed  dataset2_back_270“”\n",
      "Renamed  dataset2_back_30“”\n",
      "Renamed  dataset2_back_300“”\n",
      "Renamed  dataset2_back_330“”\n",
      "Renamed  dataset2_back_360“”\n",
      "Renamed  dataset2_back_390“”\n",
      "Renamed  dataset2_back_420“”\n",
      "Renamed  dataset2_back_450“”\n",
      "Renamed  dataset2_back_480“”\n",
      "Renamed  dataset2_back_510“”\n",
      "Renamed  dataset2_back_540“”\n",
      "Renamed  dataset2_back_570“”\n",
      "Renamed  dataset2_back_60“”\n",
      "Renamed  dataset2_back_600“”\n",
      "Renamed  dataset2_back_630“”\n",
      "Renamed  dataset2_back_660“”\n",
      "Renamed  dataset2_back_690“”\n",
      "Renamed  dataset2_back_720“”\n",
      "Renamed  dataset2_back_750“”\n",
      "Renamed  dataset2_back_780“”\n",
      "Renamed  dataset2_back_810“”\n",
      "Renamed  dataset2_back_840“”\n",
      "Renamed  dataset2_back_870“”\n",
      "Renamed  dataset2_back_90“”\n",
      "Renamed  dataset2_back_900“”\n",
      "Renamed  dataset2_back_930“”\n",
      "Renamed  dataset2_back_960“”\n",
      "Renamed  dataset2_back_990“”\n",
      "Renamed  dataset2_front_0“”\n",
      "Renamed  dataset2_front_1020“”\n",
      "Renamed  dataset2_front_1050“”\n",
      "Renamed  dataset2_front_1080“”\n",
      "Renamed  dataset2_front_1110“”\n",
      "Renamed  dataset2_front_1140“”\n",
      "Renamed  dataset2_front_1170“”\n",
      "Renamed  dataset2_front_120“”\n",
      "Renamed  dataset2_front_1200“”\n",
      "Renamed  dataset2_front_1230“”\n",
      "Renamed  dataset2_front_1260“”\n",
      "Renamed  dataset2_front_1290“”\n",
      "Renamed  dataset2_front_1320“”\n",
      "Renamed  dataset2_front_1350“”\n",
      "Renamed  dataset2_front_1380“”\n",
      "Renamed  dataset2_front_1410“”\n",
      "Renamed  dataset2_front_1440“”\n",
      "Renamed  dataset2_front_1470“”\n",
      "Renamed  dataset2_front_150“”\n",
      "Renamed  dataset2_front_1500“”\n",
      "Renamed  dataset2_front_180“”\n",
      "Renamed  dataset2_front_210“”\n",
      "Renamed  dataset2_front_240“”\n",
      "Renamed  dataset2_front_270“”\n",
      "Renamed  dataset2_front_30“”\n",
      "Renamed  dataset2_front_300“”\n",
      "Renamed  dataset2_front_330“”\n",
      "Renamed  dataset2_front_360“”\n",
      "Renamed  dataset2_front_390“”\n",
      "Renamed  dataset2_front_420“”\n",
      "Renamed  dataset2_front_450“”\n",
      "Renamed  dataset2_front_480“”\n",
      "Renamed  dataset2_front_510“”\n",
      "Renamed  dataset2_front_540“”\n",
      "Renamed  dataset2_front_570“”\n",
      "Renamed  dataset2_front_60“”\n",
      "Renamed  dataset2_front_600“”\n",
      "Renamed  dataset2_front_630“”\n",
      "Renamed  dataset2_front_660“”\n",
      "Renamed  dataset2_front_690“”\n",
      "Renamed  dataset2_front_720“”\n",
      "Renamed  dataset2_front_750“”\n",
      "Renamed  dataset2_front_780“”\n",
      "Renamed  dataset2_front_810“”\n",
      "Renamed  dataset2_front_840“”\n",
      "Renamed  dataset2_front_870“”\n",
      "Renamed  dataset2_front_90“”\n",
      "Renamed  dataset2_front_900“”\n",
      "Renamed  dataset2_front_930“”\n",
      "Renamed  dataset2_front_960“”\n",
      "Renamed  dataset2_front_990“”\n",
      "Renamed  dataset3_back_0“”\n",
      "Renamed  dataset3_back_1020“”\n",
      "Renamed  dataset3_back_1050“”\n",
      "Renamed  dataset3_back_1080“”\n",
      "Renamed  dataset3_back_1110“”\n",
      "Renamed  dataset3_back_1140“”\n",
      "Renamed  dataset3_back_1170“”\n",
      "Renamed  dataset3_back_120“”\n",
      "Renamed  dataset3_back_1200“”\n",
      "Renamed  dataset3_back_1230“”\n",
      "Renamed  dataset3_back_1260“”\n",
      "Renamed  dataset3_back_1290“”\n",
      "Renamed  dataset3_back_1320“”\n",
      "Renamed  dataset3_back_150“”\n",
      "Renamed  dataset3_back_180“”\n",
      "Renamed  dataset3_back_210“”\n",
      "Renamed  dataset3_back_240“”\n",
      "Renamed  dataset3_back_270“”\n",
      "Renamed  dataset3_back_30“”\n",
      "Renamed  dataset3_back_300“”\n",
      "Renamed  dataset3_back_330“”\n",
      "Renamed  dataset3_back_360“”\n",
      "Renamed  dataset3_back_390“”\n",
      "Renamed  dataset3_back_420“”\n",
      "Renamed  dataset3_back_450“”\n",
      "Renamed  dataset3_back_480“”\n",
      "Renamed  dataset3_back_510“”\n",
      "Renamed  dataset3_back_540“”\n",
      "Renamed  dataset3_back_570“”\n",
      "Renamed  dataset3_back_60“”\n",
      "Renamed  dataset3_back_600“”\n",
      "Renamed  dataset3_back_630“”\n",
      "Renamed  dataset3_back_660“”\n",
      "Renamed  dataset3_back_690“”\n",
      "Renamed  dataset3_back_720“”\n",
      "Renamed  dataset3_back_750“”\n",
      "Renamed  dataset3_back_780“”\n",
      "Renamed  dataset3_back_810“”\n",
      "Renamed  dataset3_back_840“”\n",
      "Renamed  dataset3_back_870“”\n",
      "Renamed  dataset3_back_90“”\n",
      "Renamed  dataset3_back_900“”\n",
      "Renamed  dataset3_back_930“”\n",
      "Renamed  dataset3_back_960“”\n",
      "Renamed  dataset3_back_990“”\n",
      "Renamed  dataset3_front_0“”\n",
      "Renamed  dataset3_front_1020“”\n",
      "Renamed  dataset3_front_1050“”\n",
      "Renamed  dataset3_front_1080“”\n",
      "Renamed  dataset3_front_1110“”\n",
      "Renamed  dataset3_front_1140“”\n",
      "Renamed  dataset3_front_1170“”\n",
      "Renamed  dataset3_front_120“”\n",
      "Renamed  dataset3_front_1200“”\n",
      "Renamed  dataset3_front_1230“”\n",
      "Renamed  dataset3_front_1260“”\n",
      "Renamed  dataset3_front_1290“”\n",
      "Renamed  dataset3_front_1320“”\n",
      "Renamed  dataset3_front_1350“”\n",
      "Renamed  dataset3_front_1380“”\n",
      "Renamed  dataset3_front_1410“”\n",
      "Renamed  dataset3_front_150“”\n",
      "Renamed  dataset3_front_180“”\n",
      "Renamed  dataset3_front_210“”\n",
      "Renamed  dataset3_front_240“”\n",
      "Renamed  dataset3_front_270“”\n",
      "Renamed  dataset3_front_30“”\n",
      "Renamed  dataset3_front_300“”\n",
      "Renamed  dataset3_front_330“”\n",
      "Renamed  dataset3_front_360“”\n",
      "Renamed  dataset3_front_390“”\n",
      "Renamed  dataset3_front_420“”\n",
      "Renamed  dataset3_front_450“”\n",
      "Renamed  dataset3_front_480“”\n",
      "Renamed  dataset3_front_510“”\n",
      "Renamed  dataset3_front_540“”\n",
      "Renamed  dataset3_front_570“”\n",
      "Renamed  dataset3_front_60“”\n",
      "Renamed  dataset3_front_600“”\n",
      "Renamed  dataset3_front_630“”\n",
      "Renamed  dataset3_front_660“”\n",
      "Renamed  dataset3_front_690“”\n",
      "Renamed  dataset3_front_720“”\n",
      "Renamed  dataset3_front_750“”\n",
      "Renamed  dataset3_front_780“”\n",
      "Renamed  dataset3_front_810“”\n",
      "Renamed  dataset3_front_840“”\n",
      "Renamed  dataset3_front_870“”\n",
      "Renamed  dataset3_front_90“”\n",
      "Renamed  dataset3_front_900“”\n",
      "Renamed  dataset3_front_930“”\n",
      "Renamed  dataset3_front_960“”\n",
      "Renamed  dataset3_front_990“”\n",
      "Renamed  dataset4_front_0“”\n",
      "Renamed  dataset4_front_1020“”\n",
      "Renamed  dataset4_front_1050“”\n",
      "Renamed  dataset4_front_1080“”\n",
      "Renamed  dataset4_front_1110“”\n",
      "Renamed  dataset4_front_1140“”\n",
      "Renamed  dataset4_front_1170“”\n",
      "Renamed  dataset4_front_120“”\n",
      "Renamed  dataset4_front_1200“”\n",
      "Renamed  dataset4_front_1230“”\n",
      "Renamed  dataset4_front_150“”\n",
      "Renamed  dataset4_front_180“”\n",
      "Renamed  dataset4_front_210“”\n",
      "Renamed  dataset4_front_240“”\n",
      "Renamed  dataset4_front_270“”\n",
      "Renamed  dataset4_front_30“”\n",
      "Renamed  dataset4_front_300“”\n",
      "Renamed  dataset4_front_330“”\n",
      "Renamed  dataset4_front_360“”\n",
      "Renamed  dataset4_front_390“”\n",
      "Renamed  dataset4_front_420“”\n",
      "Renamed  dataset4_front_450“”\n",
      "Renamed  dataset4_front_480“”\n",
      "Renamed  dataset4_front_510“”\n",
      "Renamed  dataset4_front_540“”\n",
      "Renamed  dataset4_front_570“”\n",
      "Renamed  dataset4_front_60“”\n",
      "Renamed  dataset4_front_600“”\n",
      "Renamed  dataset4_front_630“”\n",
      "Renamed  dataset4_front_660“”\n",
      "Renamed  dataset4_front_690“”\n",
      "Renamed  dataset4_front_720“”\n",
      "Renamed  dataset4_front_750“”\n",
      "Renamed  dataset4_front_780“”\n",
      "Renamed  dataset4_front_810“”\n",
      "Renamed  dataset4_front_840“”\n",
      "Renamed  dataset4_front_870“”\n",
      "Renamed  dataset4_front_90“”\n",
      "Renamed  dataset4_front_900“”\n",
      "Renamed  dataset4_front_930“”\n",
      "Renamed  dataset4_front_960“”\n",
      "Renamed  dataset4_front_990“”\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "# 指定文件夹路径\n",
    "folder_path = r\"E:\\download\\MinneApple-master\\MinneApple-master\\MinneApple-master\\predict2outputByjupyter\"\n",
    "\n",
    "# 遍历文件夹中的所有文件\n",
    "for filename in os.listdir(folder_path):\n",
    "    # 检查文件名是否以 \"_mask.png\" 结尾\n",
    "    \n",
    "        old_file_path = os.path.join(folder_path, filename)\n",
    "        new_file_path = os.path.join(folder_path, filename+\".png\")\n",
    "        # 重命名文件\n",
    "        os.rename(old_file_path, new_file_path)\n",
    "        print(f\"Renamed  {filename}“”\" )"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-03-19T23:02:16.254089400Z",
     "start_time": "2025-03-19T23:02:16.053507800Z"
    }
   },
   "id": "8720b7c53090403c",
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "f08e1e5ca0a7423f"
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "82214b7dec44a2ec"
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\anaconda3\\envs\\torch2\\lib\\site-packages\\torchvision\\models\\_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.\n",
      "  warnings.warn(\n",
      "d:\\anaconda3\\envs\\torch2\\lib\\site-packages\\torchvision\\models\\_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=MaskRCNN_ResNet50_FPN_Weights.COCO_V1`. You can also use `weights=MaskRCNN_ResNet50_FPN_Weights.DEFAULT` to get the most up-to-date weights.\n",
      "  warnings.warn(msg)\n"
     ]
    },
    {
     "ename": "RuntimeError",
     "evalue": "Error(s) in loading state_dict for MaskRCNN:\n\tMissing key(s) in state_dict: \"backbone.body.conv1.weight\", \"backbone.body.bn1.weight\", \"backbone.body.bn1.bias\", \"backbone.body.bn1.running_mean\", \"backbone.body.bn1.running_var\", \"backbone.body.layer1.0.conv1.weight\", \"backbone.body.layer1.0.bn1.weight\", \"backbone.body.layer1.0.bn1.bias\", \"backbone.body.layer1.0.bn1.running_mean\", \"backbone.body.layer1.0.bn1.running_var\", \"backbone.body.layer1.0.conv2.weight\", \"backbone.body.layer1.0.bn2.weight\", \"backbone.body.layer1.0.bn2.bias\", \"backbone.body.layer1.0.bn2.running_mean\", \"backbone.body.layer1.0.bn2.running_var\", \"backbone.body.layer1.0.conv3.weight\", \"backbone.body.layer1.0.bn3.weight\", \"backbone.body.layer1.0.bn3.bias\", \"backbone.body.layer1.0.bn3.running_mean\", \"backbone.body.layer1.0.bn3.running_var\", \"backbone.body.layer1.0.downsample.0.weight\", \"backbone.body.layer1.0.downsample.1.weight\", \"backbone.body.layer1.0.downsample.1.bias\", \"backbone.body.layer1.0.downsample.1.running_mean\", \"backbone.body.layer1.0.downsample.1.running_var\", \"backbone.body.layer1.1.conv1.weight\", \"backbone.body.layer1.1.bn1.weight\", \"backbone.body.layer1.1.bn1.bias\", \"backbone.body.layer1.1.bn1.running_mean\", \"backbone.body.layer1.1.bn1.running_var\", \"backbone.body.layer1.1.conv2.weight\", \"backbone.body.layer1.1.bn2.weight\", \"backbone.body.layer1.1.bn2.bias\", \"backbone.body.layer1.1.bn2.running_mean\", \"backbone.body.layer1.1.bn2.running_var\", \"backbone.body.layer1.1.conv3.weight\", \"backbone.body.layer1.1.bn3.weight\", \"backbone.body.layer1.1.bn3.bias\", \"backbone.body.layer1.1.bn3.running_mean\", \"backbone.body.layer1.1.bn3.running_var\", \"backbone.body.layer1.2.conv1.weight\", \"backbone.body.layer1.2.bn1.weight\", \"backbone.body.layer1.2.bn1.bias\", \"backbone.body.layer1.2.bn1.running_mean\", \"backbone.body.layer1.2.bn1.running_var\", \"backbone.body.layer1.2.conv2.weight\", \"backbone.body.layer1.2.bn2.weight\", \"backbone.body.layer1.2.bn2.bias\", \"backbone.body.layer1.2.bn2.running_mean\", \"backbone.body.layer1.2.bn2.running_var\", \"backbone.body.layer1.2.conv3.weight\", \"backbone.body.layer1.2.bn3.weight\", \"backbone.body.layer1.2.bn3.bias\", \"backbone.body.layer1.2.bn3.running_mean\", \"backbone.body.layer1.2.bn3.running_var\", \"backbone.body.layer2.0.conv1.weight\", \"backbone.body.layer2.0.bn1.weight\", \"backbone.body.layer2.0.bn1.bias\", \"backbone.body.layer2.0.bn1.running_mean\", \"backbone.body.layer2.0.bn1.running_var\", \"backbone.body.layer2.0.conv2.weight\", \"backbone.body.layer2.0.bn2.weight\", \"backbone.body.layer2.0.bn2.bias\", \"backbone.body.layer2.0.bn2.running_mean\", \"backbone.body.layer2.0.bn2.running_var\", \"backbone.body.layer2.0.conv3.weight\", \"backbone.body.layer2.0.bn3.weight\", \"backbone.body.layer2.0.bn3.bias\", \"backbone.body.layer2.0.bn3.running_mean\", \"backbone.body.layer2.0.bn3.running_var\", \"backbone.body.layer2.0.downsample.0.weight\", \"backbone.body.layer2.0.downsample.1.weight\", \"backbone.body.layer2.0.downsample.1.bias\", \"backbone.body.layer2.0.downsample.1.running_mean\", \"backbone.body.layer2.0.downsample.1.running_var\", \"backbone.body.layer2.1.conv1.weight\", \"backbone.body.layer2.1.bn1.weight\", \"backbone.body.layer2.1.bn1.bias\", \"backbone.body.layer2.1.bn1.running_mean\", \"backbone.body.layer2.1.bn1.running_var\", \"backbone.body.layer2.1.conv2.weight\", \"backbone.body.layer2.1.bn2.weight\", \"backbone.body.layer2.1.bn2.bias\", \"backbone.body.layer2.1.bn2.running_mean\", \"backbone.body.layer2.1.bn2.running_var\", \"backbone.body.layer2.1.conv3.weight\", \"backbone.body.layer2.1.bn3.weight\", \"backbone.body.layer2.1.bn3.bias\", \"backbone.body.layer2.1.bn3.running_mean\", \"backbone.body.layer2.1.bn3.running_var\", \"backbone.body.layer2.2.conv1.weight\", \"backbone.body.layer2.2.bn1.weight\", \"backbone.body.layer2.2.bn1.bias\", \"backbone.body.layer2.2.bn1.running_mean\", \"backbone.body.layer2.2.bn1.running_var\", \"backbone.body.layer2.2.conv2.weight\", \"backbone.body.layer2.2.bn2.weight\", \"backbone.body.layer2.2.bn2.bias\", \"backbone.body.layer2.2.bn2.running_mean\", \"backbone.body.layer2.2.bn2.running_var\", \"backbone.body.layer2.2.conv3.weight\", \"backbone.body.layer2.2.bn3.weight\", \"backbone.body.layer2.2.bn3.bias\", \"backbone.body.layer2.2.bn3.running_mean\", \"backbone.body.layer2.2.bn3.running_var\", \"backbone.body.layer2.3.conv1.weight\", \"backbone.body.layer2.3.bn1.weight\", \"backbone.body.layer2.3.bn1.bias\", \"backbone.body.layer2.3.bn1.running_mean\", \"backbone.body.layer2.3.bn1.running_var\", \"backbone.body.layer2.3.conv2.weight\", \"backbone.body.layer2.3.bn2.weight\", \"backbone.body.layer2.3.bn2.bias\", \"backbone.body.layer2.3.bn2.running_mean\", \"backbone.body.layer2.3.bn2.running_var\", \"backbone.body.layer2.3.conv3.weight\", \"backbone.body.layer2.3.bn3.weight\", \"backbone.body.layer2.3.bn3.bias\", \"backbone.body.layer2.3.bn3.running_mean\", \"backbone.body.layer2.3.bn3.running_var\", \"backbone.body.layer3.0.conv1.weight\", \"backbone.body.layer3.0.bn1.weight\", \"backbone.body.layer3.0.bn1.bias\", \"backbone.body.layer3.0.bn1.running_mean\", \"backbone.body.layer3.0.bn1.running_var\", \"backbone.body.layer3.0.conv2.weight\", \"backbone.body.layer3.0.bn2.weight\", \"backbone.body.layer3.0.bn2.bias\", \"backbone.body.layer3.0.bn2.running_mean\", \"backbone.body.layer3.0.bn2.running_var\", \"backbone.body.layer3.0.conv3.weight\", \"backbone.body.layer3.0.bn3.weight\", \"backbone.body.layer3.0.bn3.bias\", \"backbone.body.layer3.0.bn3.running_mean\", \"backbone.body.layer3.0.bn3.running_var\", \"backbone.body.layer3.0.downsample.0.weight\", \"backbone.body.layer3.0.downsample.1.weight\", \"backbone.body.layer3.0.downsample.1.bias\", \"backbone.body.layer3.0.downsample.1.running_mean\", \"backbone.body.layer3.0.downsample.1.running_var\", \"backbone.body.layer3.1.conv1.weight\", \"backbone.body.layer3.1.bn1.weight\", \"backbone.body.layer3.1.bn1.bias\", \"backbone.body.layer3.1.bn1.running_mean\", \"backbone.body.layer3.1.bn1.running_var\", \"backbone.body.layer3.1.conv2.weight\", \"backbone.body.layer3.1.bn2.weight\", \"backbone.body.layer3.1.bn2.bias\", \"backbone.body.layer3.1.bn2.running_mean\", \"backbone.body.layer3.1.bn2.running_var\", \"backbone.body.layer3.1.conv3.weight\", \"backbone.body.layer3.1.bn3.weight\", \"backbone.body.layer3.1.bn3.bias\", \"backbone.body.layer3.1.bn3.running_mean\", \"backbone.body.layer3.1.bn3.running_var\", \"backbone.body.layer3.2.conv1.weight\", \"backbone.body.layer3.2.bn1.weight\", \"backbone.body.layer3.2.bn1.bias\", \"backbone.body.layer3.2.bn1.running_mean\", \"backbone.body.layer3.2.bn1.running_var\", \"backbone.body.layer3.2.conv2.weight\", \"backbone.body.layer3.2.bn2.weight\", \"backbone.body.layer3.2.bn2.bias\", \"backbone.body.layer3.2.bn2.running_mean\", \"backbone.body.layer3.2.bn2.running_var\", \"backbone.body.layer3.2.conv3.weight\", \"backbone.body.layer3.2.bn3.weight\", \"backbone.body.layer3.2.bn3.bias\", \"backbone.body.layer3.2.bn3.running_mean\", \"backbone.body.layer3.2.bn3.running_var\", \"backbone.body.layer3.3.conv1.weight\", \"backbone.body.layer3.3.bn1.weight\", \"backbone.body.layer3.3.bn1.bias\", \"backbone.body.layer3.3.bn1.running_mean\", \"backbone.body.layer3.3.bn1.running_var\", \"backbone.body.layer3.3.conv2.weight\", \"backbone.body.layer3.3.bn2.weight\", \"backbone.body.layer3.3.bn2.bias\", \"backbone.body.layer3.3.bn2.running_mean\", \"backbone.body.layer3.3.bn2.running_var\", \"backbone.body.layer3.3.conv3.weight\", \"backbone.body.layer3.3.bn3.weight\", \"backbone.body.layer3.3.bn3.bias\", \"backbone.body.layer3.3.bn3.running_mean\", \"backbone.body.layer3.3.bn3.running_var\", \"backbone.body.layer3.4.conv1.weight\", \"backbone.body.layer3.4.bn1.weight\", \"backbone.body.layer3.4.bn1.bias\", \"backbone.body.layer3.4.bn1.running_mean\", \"backbone.body.layer3.4.bn1.running_var\", \"backbone.body.layer3.4.conv2.weight\", \"backbone.body.layer3.4.bn2.weight\", \"backbone.body.layer3.4.bn2.bias\", \"backbone.body.layer3.4.bn2.running_mean\", \"backbone.body.layer3.4.bn2.running_var\", \"backbone.body.layer3.4.conv3.weight\", \"backbone.body.layer3.4.bn3.weight\", \"backbone.body.layer3.4.bn3.bias\", \"backbone.body.layer3.4.bn3.running_mean\", \"backbone.body.layer3.4.bn3.running_var\", \"backbone.body.layer3.5.conv1.weight\", \"backbone.body.layer3.5.bn1.weight\", \"backbone.body.layer3.5.bn1.bias\", \"backbone.body.layer3.5.bn1.running_mean\", \"backbone.body.layer3.5.bn1.running_var\", \"backbone.body.layer3.5.conv2.weight\", \"backbone.body.layer3.5.bn2.weight\", \"backbone.body.layer3.5.bn2.bias\", \"backbone.body.layer3.5.bn2.running_mean\", \"backbone.body.layer3.5.bn2.running_var\", \"backbone.body.layer3.5.conv3.weight\", \"backbone.body.layer3.5.bn3.weight\", \"backbone.body.layer3.5.bn3.bias\", \"backbone.body.layer3.5.bn3.running_mean\", \"backbone.body.layer3.5.bn3.running_var\", \"backbone.body.layer4.0.conv1.weight\", \"backbone.body.layer4.0.bn1.weight\", \"backbone.body.layer4.0.bn1.bias\", \"backbone.body.layer4.0.bn1.running_mean\", \"backbone.body.layer4.0.bn1.running_var\", \"backbone.body.layer4.0.conv2.weight\", \"backbone.body.layer4.0.bn2.weight\", \"backbone.body.layer4.0.bn2.bias\", \"backbone.body.layer4.0.bn2.running_mean\", \"backbone.body.layer4.0.bn2.running_var\", \"backbone.body.layer4.0.conv3.weight\", \"backbone.body.layer4.0.bn3.weight\", \"backbone.body.layer4.0.bn3.bias\", \"backbone.body.layer4.0.bn3.running_mean\", \"backbone.body.layer4.0.bn3.running_var\", \"backbone.body.layer4.0.downsample.0.weight\", \"backbone.body.layer4.0.downsample.1.weight\", \"backbone.body.layer4.0.downsample.1.bias\", \"backbone.body.layer4.0.downsample.1.running_mean\", \"backbone.body.layer4.0.downsample.1.running_var\", \"backbone.body.layer4.1.conv1.weight\", \"backbone.body.layer4.1.bn1.weight\", \"backbone.body.layer4.1.bn1.bias\", \"backbone.body.layer4.1.bn1.running_mean\", \"backbone.body.layer4.1.bn1.running_var\", \"backbone.body.layer4.1.conv2.weight\", \"backbone.body.layer4.1.bn2.weight\", \"backbone.body.layer4.1.bn2.bias\", \"backbone.body.layer4.1.bn2.running_mean\", \"backbone.body.layer4.1.bn2.running_var\", \"backbone.body.layer4.1.conv3.weight\", \"backbone.body.layer4.1.bn3.weight\", \"backbone.body.layer4.1.bn3.bias\", \"backbone.body.layer4.1.bn3.running_mean\", \"backbone.body.layer4.1.bn3.running_var\", \"backbone.body.layer4.2.conv1.weight\", \"backbone.body.layer4.2.bn1.weight\", \"backbone.body.layer4.2.bn1.bias\", \"backbone.body.layer4.2.bn1.running_mean\", \"backbone.body.layer4.2.bn1.running_var\", \"backbone.body.layer4.2.conv2.weight\", \"backbone.body.layer4.2.bn2.weight\", \"backbone.body.layer4.2.bn2.bias\", \"backbone.body.layer4.2.bn2.running_mean\", \"backbone.body.layer4.2.bn2.running_var\", \"backbone.body.layer4.2.conv3.weight\", \"backbone.body.layer4.2.bn3.weight\", \"backbone.body.layer4.2.bn3.bias\", \"backbone.body.layer4.2.bn3.running_mean\", \"backbone.body.layer4.2.bn3.running_var\", \"backbone.fpn.inner_blocks.0.0.weight\", \"backbone.fpn.inner_blocks.0.0.bias\", \"backbone.fpn.inner_blocks.1.0.weight\", \"backbone.fpn.inner_blocks.1.0.bias\", \"backbone.fpn.inner_blocks.2.0.weight\", \"backbone.fpn.inner_blocks.2.0.bias\", \"backbone.fpn.inner_blocks.3.0.weight\", \"backbone.fpn.inner_blocks.3.0.bias\", \"backbone.fpn.layer_blocks.0.0.weight\", \"backbone.fpn.layer_blocks.0.0.bias\", \"backbone.fpn.layer_blocks.1.0.weight\", \"backbone.fpn.layer_blocks.1.0.bias\", \"backbone.fpn.layer_blocks.2.0.weight\", \"backbone.fpn.layer_blocks.2.0.bias\", \"backbone.fpn.layer_blocks.3.0.weight\", \"backbone.fpn.layer_blocks.3.0.bias\", \"rpn.head.conv.0.0.weight\", \"rpn.head.conv.0.0.bias\", \"rpn.head.cls_logits.weight\", \"rpn.head.cls_logits.bias\", \"rpn.head.bbox_pred.weight\", \"rpn.head.bbox_pred.bias\", \"roi_heads.box_head.fc6.weight\", \"roi_heads.box_head.fc6.bias\", \"roi_heads.box_head.fc7.weight\", \"roi_heads.box_head.fc7.bias\", \"roi_heads.box_predictor.cls_score.weight\", \"roi_heads.box_predictor.cls_score.bias\", \"roi_heads.box_predictor.bbox_pred.weight\", \"roi_heads.box_predictor.bbox_pred.bias\", \"roi_heads.mask_head.0.0.weight\", \"roi_heads.mask_head.0.0.bias\", \"roi_heads.mask_head.1.0.weight\", \"roi_heads.mask_head.1.0.bias\", \"roi_heads.mask_head.2.0.weight\", \"roi_heads.mask_head.2.0.bias\", \"roi_heads.mask_head.3.0.weight\", \"roi_heads.mask_head.3.0.bias\", \"roi_heads.mask_predictor.conv5_mask.weight\", \"roi_heads.mask_predictor.conv5_mask.bias\", \"roi_heads.mask_predictor.mask_fcn_logits.weight\", \"roi_heads.mask_predictor.mask_fcn_logits.bias\". \n\tUnexpected key(s) in state_dict: \"epoch\", \"model\", \"optimizer\", \"lr_scheduler\", \"ap\". ",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mRuntimeError\u001B[0m                              Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[1], line 14\u001B[0m\n\u001B[0;32m     11\u001B[0m state_dict \u001B[38;5;241m=\u001B[39m torch\u001B[38;5;241m.\u001B[39mload(dict_path)\n\u001B[0;32m     13\u001B[0m \u001B[38;5;66;03m# 将字典加载到模型中\u001B[39;00m\n\u001B[1;32m---> 14\u001B[0m \u001B[43mmodel\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mload_state_dict\u001B[49m\u001B[43m(\u001B[49m\u001B[43mstate_dict\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m     16\u001B[0m \u001B[38;5;66;03m# 保存完整模型\u001B[39;00m\n\u001B[0;32m     17\u001B[0m model_path \u001B[38;5;241m=\u001B[39m  \u001B[38;5;124mr\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mE:\u001B[39m\u001B[38;5;124m\\\u001B[39m\u001B[38;5;124mAIproject\u001B[39m\u001B[38;5;124m\\\u001B[39m\u001B[38;5;124mproject1\u001B[39m\u001B[38;5;124m\\\u001B[39m\u001B[38;5;124mfastApiProject\u001B[39m\u001B[38;5;124m\\\u001B[39m\u001B[38;5;124mbest_model1.pth\u001B[39m\u001B[38;5;124m'\u001B[39m\n",
      "File \u001B[1;32md:\\anaconda3\\envs\\torch2\\lib\\site-packages\\torch\\nn\\modules\\module.py:2041\u001B[0m, in \u001B[0;36mModule.load_state_dict\u001B[1;34m(self, state_dict, strict)\u001B[0m\n\u001B[0;32m   2036\u001B[0m         error_msgs\u001B[38;5;241m.\u001B[39minsert(\n\u001B[0;32m   2037\u001B[0m             \u001B[38;5;241m0\u001B[39m, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mMissing key(s) in state_dict: \u001B[39m\u001B[38;5;132;01m{}\u001B[39;00m\u001B[38;5;124m. \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;241m.\u001B[39mformat(\n\u001B[0;32m   2038\u001B[0m                 \u001B[38;5;124m'\u001B[39m\u001B[38;5;124m, \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;241m.\u001B[39mjoin(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;241m.\u001B[39mformat(k) \u001B[38;5;28;01mfor\u001B[39;00m k \u001B[38;5;129;01min\u001B[39;00m missing_keys)))\n\u001B[0;32m   2040\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mlen\u001B[39m(error_msgs) \u001B[38;5;241m>\u001B[39m \u001B[38;5;241m0\u001B[39m:\n\u001B[1;32m-> 2041\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mRuntimeError\u001B[39;00m(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mError(s) in loading state_dict for \u001B[39m\u001B[38;5;132;01m{}\u001B[39;00m\u001B[38;5;124m:\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;130;01m\\t\u001B[39;00m\u001B[38;5;132;01m{}\u001B[39;00m\u001B[38;5;124m'\u001B[39m\u001B[38;5;241m.\u001B[39mformat(\n\u001B[0;32m   2042\u001B[0m                        \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m\u001B[38;5;18m__class__\u001B[39m\u001B[38;5;241m.\u001B[39m\u001B[38;5;18m__name__\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;130;01m\\t\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;241m.\u001B[39mjoin(error_msgs)))\n\u001B[0;32m   2043\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m _IncompatibleKeys(missing_keys, unexpected_keys)\n",
      "\u001B[1;31mRuntimeError\u001B[0m: Error(s) in loading state_dict for MaskRCNN:\n\tMissing key(s) in state_dict: \"backbone.body.conv1.weight\", \"backbone.body.bn1.weight\", \"backbone.body.bn1.bias\", \"backbone.body.bn1.running_mean\", \"backbone.body.bn1.running_var\", \"backbone.body.layer1.0.conv1.weight\", \"backbone.body.layer1.0.bn1.weight\", \"backbone.body.layer1.0.bn1.bias\", \"backbone.body.layer1.0.bn1.running_mean\", \"backbone.body.layer1.0.bn1.running_var\", \"backbone.body.layer1.0.conv2.weight\", \"backbone.body.layer1.0.bn2.weight\", \"backbone.body.layer1.0.bn2.bias\", \"backbone.body.layer1.0.bn2.running_mean\", \"backbone.body.layer1.0.bn2.running_var\", \"backbone.body.layer1.0.conv3.weight\", \"backbone.body.layer1.0.bn3.weight\", \"backbone.body.layer1.0.bn3.bias\", \"backbone.body.layer1.0.bn3.running_mean\", \"backbone.body.layer1.0.bn3.running_var\", \"backbone.body.layer1.0.downsample.0.weight\", \"backbone.body.layer1.0.downsample.1.weight\", \"backbone.body.layer1.0.downsample.1.bias\", \"backbone.body.layer1.0.downsample.1.running_mean\", \"backbone.body.layer1.0.downsample.1.running_var\", \"backbone.body.layer1.1.conv1.weight\", \"backbone.body.layer1.1.bn1.weight\", \"backbone.body.layer1.1.bn1.bias\", \"backbone.body.layer1.1.bn1.running_mean\", \"backbone.body.layer1.1.bn1.running_var\", \"backbone.body.layer1.1.conv2.weight\", \"backbone.body.layer1.1.bn2.weight\", \"backbone.body.layer1.1.bn2.bias\", \"backbone.body.layer1.1.bn2.running_mean\", \"backbone.body.layer1.1.bn2.running_var\", \"backbone.body.layer1.1.conv3.weight\", \"backbone.body.layer1.1.bn3.weight\", \"backbone.body.layer1.1.bn3.bias\", \"backbone.body.layer1.1.bn3.running_mean\", \"backbone.body.layer1.1.bn3.running_var\", \"backbone.body.layer1.2.conv1.weight\", \"backbone.body.layer1.2.bn1.weight\", \"backbone.body.layer1.2.bn1.bias\", \"backbone.body.layer1.2.bn1.running_mean\", \"backbone.body.layer1.2.bn1.running_var\", \"backbone.body.layer1.2.conv2.weight\", \"backbone.body.layer1.2.bn2.weight\", \"backbone.body.layer1.2.bn2.bias\", \"backbone.body.layer1.2.bn2.running_mean\", \"backbone.body.layer1.2.bn2.running_var\", \"backbone.body.layer1.2.conv3.weight\", \"backbone.body.layer1.2.bn3.weight\", \"backbone.body.layer1.2.bn3.bias\", \"backbone.body.layer1.2.bn3.running_mean\", \"backbone.body.layer1.2.bn3.running_var\", \"backbone.body.layer2.0.conv1.weight\", \"backbone.body.layer2.0.bn1.weight\", \"backbone.body.layer2.0.bn1.bias\", \"backbone.body.layer2.0.bn1.running_mean\", \"backbone.body.layer2.0.bn1.running_var\", \"backbone.body.layer2.0.conv2.weight\", \"backbone.body.layer2.0.bn2.weight\", \"backbone.body.layer2.0.bn2.bias\", \"backbone.body.layer2.0.bn2.running_mean\", \"backbone.body.layer2.0.bn2.running_var\", \"backbone.body.layer2.0.conv3.weight\", \"backbone.body.layer2.0.bn3.weight\", \"backbone.body.layer2.0.bn3.bias\", \"backbone.body.layer2.0.bn3.running_mean\", \"backbone.body.layer2.0.bn3.running_var\", \"backbone.body.layer2.0.downsample.0.weight\", \"backbone.body.layer2.0.downsample.1.weight\", \"backbone.body.layer2.0.downsample.1.bias\", \"backbone.body.layer2.0.downsample.1.running_mean\", \"backbone.body.layer2.0.downsample.1.running_var\", \"backbone.body.layer2.1.conv1.weight\", \"backbone.body.layer2.1.bn1.weight\", \"backbone.body.layer2.1.bn1.bias\", \"backbone.body.layer2.1.bn1.running_mean\", \"backbone.body.layer2.1.bn1.running_var\", \"backbone.body.layer2.1.conv2.weight\", \"backbone.body.layer2.1.bn2.weight\", \"backbone.body.layer2.1.bn2.bias\", \"backbone.body.layer2.1.bn2.running_mean\", \"backbone.body.layer2.1.bn2.running_var\", \"backbone.body.layer2.1.conv3.weight\", \"backbone.body.layer2.1.bn3.weight\", \"backbone.body.layer2.1.bn3.bias\", \"backbone.body.layer2.1.bn3.running_mean\", \"backbone.body.layer2.1.bn3.running_var\", \"backbone.body.layer2.2.conv1.weight\", \"backbone.body.layer2.2.bn1.weight\", \"backbone.body.layer2.2.bn1.bias\", \"backbone.body.layer2.2.bn1.running_mean\", \"backbone.body.layer2.2.bn1.running_var\", \"backbone.body.layer2.2.conv2.weight\", \"backbone.body.layer2.2.bn2.weight\", \"backbone.body.layer2.2.bn2.bias\", \"backbone.body.layer2.2.bn2.running_mean\", \"backbone.body.layer2.2.bn2.running_var\", \"backbone.body.layer2.2.conv3.weight\", \"backbone.body.layer2.2.bn3.weight\", \"backbone.body.layer2.2.bn3.bias\", \"backbone.body.layer2.2.bn3.running_mean\", \"backbone.body.layer2.2.bn3.running_var\", \"backbone.body.layer2.3.conv1.weight\", \"backbone.body.layer2.3.bn1.weight\", \"backbone.body.layer2.3.bn1.bias\", \"backbone.body.layer2.3.bn1.running_mean\", \"backbone.body.layer2.3.bn1.running_var\", \"backbone.body.layer2.3.conv2.weight\", \"backbone.body.layer2.3.bn2.weight\", \"backbone.body.layer2.3.bn2.bias\", \"backbone.body.layer2.3.bn2.running_mean\", \"backbone.body.layer2.3.bn2.running_var\", \"backbone.body.layer2.3.conv3.weight\", \"backbone.body.layer2.3.bn3.weight\", \"backbone.body.layer2.3.bn3.bias\", \"backbone.body.layer2.3.bn3.running_mean\", \"backbone.body.layer2.3.bn3.running_var\", \"backbone.body.layer3.0.conv1.weight\", \"backbone.body.layer3.0.bn1.weight\", \"backbone.body.layer3.0.bn1.bias\", \"backbone.body.layer3.0.bn1.running_mean\", \"backbone.body.layer3.0.bn1.running_var\", \"backbone.body.layer3.0.conv2.weight\", \"backbone.body.layer3.0.bn2.weight\", \"backbone.body.layer3.0.bn2.bias\", \"backbone.body.layer3.0.bn2.running_mean\", \"backbone.body.layer3.0.bn2.running_var\", \"backbone.body.layer3.0.conv3.weight\", \"backbone.body.layer3.0.bn3.weight\", \"backbone.body.layer3.0.bn3.bias\", \"backbone.body.layer3.0.bn3.running_mean\", \"backbone.body.layer3.0.bn3.running_var\", \"backbone.body.layer3.0.downsample.0.weight\", \"backbone.body.layer3.0.downsample.1.weight\", \"backbone.body.layer3.0.downsample.1.bias\", \"backbone.body.layer3.0.downsample.1.running_mean\", \"backbone.body.layer3.0.downsample.1.running_var\", \"backbone.body.layer3.1.conv1.weight\", \"backbone.body.layer3.1.bn1.weight\", \"backbone.body.layer3.1.bn1.bias\", \"backbone.body.layer3.1.bn1.running_mean\", \"backbone.body.layer3.1.bn1.running_var\", \"backbone.body.layer3.1.conv2.weight\", \"backbone.body.layer3.1.bn2.weight\", \"backbone.body.layer3.1.bn2.bias\", \"backbone.body.layer3.1.bn2.running_mean\", \"backbone.body.layer3.1.bn2.running_var\", \"backbone.body.layer3.1.conv3.weight\", \"backbone.body.layer3.1.bn3.weight\", \"backbone.body.layer3.1.bn3.bias\", \"backbone.body.layer3.1.bn3.running_mean\", \"backbone.body.layer3.1.bn3.running_var\", \"backbone.body.layer3.2.conv1.weight\", \"backbone.body.layer3.2.bn1.weight\", \"backbone.body.layer3.2.bn1.bias\", \"backbone.body.layer3.2.bn1.running_mean\", \"backbone.body.layer3.2.bn1.running_var\", \"backbone.body.layer3.2.conv2.weight\", \"backbone.body.layer3.2.bn2.weight\", \"backbone.body.layer3.2.bn2.bias\", \"backbone.body.layer3.2.bn2.running_mean\", \"backbone.body.layer3.2.bn2.running_var\", \"backbone.body.layer3.2.conv3.weight\", \"backbone.body.layer3.2.bn3.weight\", \"backbone.body.layer3.2.bn3.bias\", \"backbone.body.layer3.2.bn3.running_mean\", \"backbone.body.layer3.2.bn3.running_var\", \"backbone.body.layer3.3.conv1.weight\", \"backbone.body.layer3.3.bn1.weight\", \"backbone.body.layer3.3.bn1.bias\", \"backbone.body.layer3.3.bn1.running_mean\", \"backbone.body.layer3.3.bn1.running_var\", \"backbone.body.layer3.3.conv2.weight\", \"backbone.body.layer3.3.bn2.weight\", \"backbone.body.layer3.3.bn2.bias\", \"backbone.body.layer3.3.bn2.running_mean\", \"backbone.body.layer3.3.bn2.running_var\", \"backbone.body.layer3.3.conv3.weight\", \"backbone.body.layer3.3.bn3.weight\", \"backbone.body.layer3.3.bn3.bias\", \"backbone.body.layer3.3.bn3.running_mean\", \"backbone.body.layer3.3.bn3.running_var\", \"backbone.body.layer3.4.conv1.weight\", \"backbone.body.layer3.4.bn1.weight\", \"backbone.body.layer3.4.bn1.bias\", \"backbone.body.layer3.4.bn1.running_mean\", \"backbone.body.layer3.4.bn1.running_var\", \"backbone.body.layer3.4.conv2.weight\", \"backbone.body.layer3.4.bn2.weight\", \"backbone.body.layer3.4.bn2.bias\", \"backbone.body.layer3.4.bn2.running_mean\", \"backbone.body.layer3.4.bn2.running_var\", \"backbone.body.layer3.4.conv3.weight\", \"backbone.body.layer3.4.bn3.weight\", \"backbone.body.layer3.4.bn3.bias\", \"backbone.body.layer3.4.bn3.running_mean\", \"backbone.body.layer3.4.bn3.running_var\", \"backbone.body.layer3.5.conv1.weight\", \"backbone.body.layer3.5.bn1.weight\", \"backbone.body.layer3.5.bn1.bias\", \"backbone.body.layer3.5.bn1.running_mean\", \"backbone.body.layer3.5.bn1.running_var\", \"backbone.body.layer3.5.conv2.weight\", \"backbone.body.layer3.5.bn2.weight\", \"backbone.body.layer3.5.bn2.bias\", \"backbone.body.layer3.5.bn2.running_mean\", \"backbone.body.layer3.5.bn2.running_var\", \"backbone.body.layer3.5.conv3.weight\", \"backbone.body.layer3.5.bn3.weight\", \"backbone.body.layer3.5.bn3.bias\", \"backbone.body.layer3.5.bn3.running_mean\", \"backbone.body.layer3.5.bn3.running_var\", \"backbone.body.layer4.0.conv1.weight\", \"backbone.body.layer4.0.bn1.weight\", \"backbone.body.layer4.0.bn1.bias\", \"backbone.body.layer4.0.bn1.running_mean\", \"backbone.body.layer4.0.bn1.running_var\", \"backbone.body.layer4.0.conv2.weight\", \"backbone.body.layer4.0.bn2.weight\", \"backbone.body.layer4.0.bn2.bias\", \"backbone.body.layer4.0.bn2.running_mean\", \"backbone.body.layer4.0.bn2.running_var\", \"backbone.body.layer4.0.conv3.weight\", \"backbone.body.layer4.0.bn3.weight\", \"backbone.body.layer4.0.bn3.bias\", \"backbone.body.layer4.0.bn3.running_mean\", \"backbone.body.layer4.0.bn3.running_var\", \"backbone.body.layer4.0.downsample.0.weight\", \"backbone.body.layer4.0.downsample.1.weight\", \"backbone.body.layer4.0.downsample.1.bias\", \"backbone.body.layer4.0.downsample.1.running_mean\", \"backbone.body.layer4.0.downsample.1.running_var\", \"backbone.body.layer4.1.conv1.weight\", \"backbone.body.layer4.1.bn1.weight\", \"backbone.body.layer4.1.bn1.bias\", \"backbone.body.layer4.1.bn1.running_mean\", \"backbone.body.layer4.1.bn1.running_var\", \"backbone.body.layer4.1.conv2.weight\", \"backbone.body.layer4.1.bn2.weight\", \"backbone.body.layer4.1.bn2.bias\", \"backbone.body.layer4.1.bn2.running_mean\", \"backbone.body.layer4.1.bn2.running_var\", \"backbone.body.layer4.1.conv3.weight\", \"backbone.body.layer4.1.bn3.weight\", \"backbone.body.layer4.1.bn3.bias\", \"backbone.body.layer4.1.bn3.running_mean\", \"backbone.body.layer4.1.bn3.running_var\", \"backbone.body.layer4.2.conv1.weight\", \"backbone.body.layer4.2.bn1.weight\", \"backbone.body.layer4.2.bn1.bias\", \"backbone.body.layer4.2.bn1.running_mean\", \"backbone.body.layer4.2.bn1.running_var\", \"backbone.body.layer4.2.conv2.weight\", \"backbone.body.layer4.2.bn2.weight\", \"backbone.body.layer4.2.bn2.bias\", \"backbone.body.layer4.2.bn2.running_mean\", \"backbone.body.layer4.2.bn2.running_var\", \"backbone.body.layer4.2.conv3.weight\", \"backbone.body.layer4.2.bn3.weight\", \"backbone.body.layer4.2.bn3.bias\", \"backbone.body.layer4.2.bn3.running_mean\", \"backbone.body.layer4.2.bn3.running_var\", \"backbone.fpn.inner_blocks.0.0.weight\", \"backbone.fpn.inner_blocks.0.0.bias\", \"backbone.fpn.inner_blocks.1.0.weight\", \"backbone.fpn.inner_blocks.1.0.bias\", \"backbone.fpn.inner_blocks.2.0.weight\", \"backbone.fpn.inner_blocks.2.0.bias\", \"backbone.fpn.inner_blocks.3.0.weight\", \"backbone.fpn.inner_blocks.3.0.bias\", \"backbone.fpn.layer_blocks.0.0.weight\", \"backbone.fpn.layer_blocks.0.0.bias\", \"backbone.fpn.layer_blocks.1.0.weight\", \"backbone.fpn.layer_blocks.1.0.bias\", \"backbone.fpn.layer_blocks.2.0.weight\", \"backbone.fpn.layer_blocks.2.0.bias\", \"backbone.fpn.layer_blocks.3.0.weight\", \"backbone.fpn.layer_blocks.3.0.bias\", \"rpn.head.conv.0.0.weight\", \"rpn.head.conv.0.0.bias\", \"rpn.head.cls_logits.weight\", \"rpn.head.cls_logits.bias\", \"rpn.head.bbox_pred.weight\", \"rpn.head.bbox_pred.bias\", \"roi_heads.box_head.fc6.weight\", \"roi_heads.box_head.fc6.bias\", \"roi_heads.box_head.fc7.weight\", \"roi_heads.box_head.fc7.bias\", \"roi_heads.box_predictor.cls_score.weight\", \"roi_heads.box_predictor.cls_score.bias\", \"roi_heads.box_predictor.bbox_pred.weight\", \"roi_heads.box_predictor.bbox_pred.bias\", \"roi_heads.mask_head.0.0.weight\", \"roi_heads.mask_head.0.0.bias\", \"roi_heads.mask_head.1.0.weight\", \"roi_heads.mask_head.1.0.bias\", \"roi_heads.mask_head.2.0.weight\", \"roi_heads.mask_head.2.0.bias\", \"roi_heads.mask_head.3.0.weight\", \"roi_heads.mask_head.3.0.bias\", \"roi_heads.mask_predictor.conv5_mask.weight\", \"roi_heads.mask_predictor.conv5_mask.bias\", \"roi_heads.mask_predictor.mask_fcn_logits.weight\", \"roi_heads.mask_predictor.mask_fcn_logits.bias\". \n\tUnexpected key(s) in state_dict: \"epoch\", \"model\", \"optimizer\", \"lr_scheduler\", \"ap\". "
     ]
    }
   ],
   "source": [
    "import torch\n",
    "from train_rcnn import get_maskrcnn_model_instance\n",
    "\n",
    "# 字典文件路径\n",
    "dict_path = r'E:\\AIproject\\project1\\fastApiProject\\best_model.pth'\n",
    "\n",
    "# 创建模型实例\n",
    "model = get_maskrcnn_model_instance(num_classes=2)\n",
    "\n",
    "# 加载字典文件\n",
    "state_dict = torch.load(dict_path)\n",
    "\n",
    "# 将字典加载到模型中\n",
    "model.load_state_dict(state_dict)\n",
    "\n",
    "# 保存完整模型\n",
    "model_path =  r'E:\\AIproject\\project1\\fastApiProject\\best_model1.pth'\n",
    "torch.save(model, model_path)\n",
    "\n",
    "print(f\"模型已成功保存到: {model_path}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-03-21T05:22:08.917011800Z",
     "start_time": "2025-03-21T05:21:58.366963300Z"
    }
   },
   "id": "119258f9a8fee078",
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "24e5738699ba0554"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
